function Features(options)
{
    var $this = this;
    this.options = $.extend(true, Features.defaults, options);
    this.setOptions = function(options){
	options = options || {};	
	this.options = $.extend(true, this.options, options);	
	return this;
    }
    this.add = function(type) {
	if (type === undefined){
	    showStatusMessage("Тип не указан", "error");
	    return false;
	}
	type = type.toLowerCase();    
	var url = $(this.options[type].urlField);	
	if (!url.length) {
	    showStatusMessage("Элемент не найден", "error");
	    return false;
	}
	disableElement(this.options[type].submitButton);
	$.ajax({
	    url: this.options[type].url,
	    dataType: "json",
	    data : {
		url : url.val(), 
		tok: Math.random()
	    },
	    success : function(data) {
		enableElement($this.options[type].submitButton);
		if (data.error !== undefined) {
		    showStatusMessage(data.error, "error");
		    return;
		}
		url.val("");
		$this.update(data, type);
	    },
	    error : errorFunction	    
	});
	return false;
    }
    this.remove = function(id, type) {
	if (!id || !type) {
	    showStatusMessage("Не указан тип или идентификатор", "error");
	    return false;
	}
	if (!confirm("Вы действительно желаете удалить эту запись?")) {
	    return false;
	}
	$.ajax({
	    url: "/ajax/removeadv",
	    dataType: "json",		
	    data: {
		id : id,
		type: type,
		tok: Math.random()
	    },
	    success : function(data) {
		if (data.error !== undefined) {
		    showStatusMessage(data.error, "error");
		    return;
		}
		if ($("#" + $this.options[type].listItem + "_" + id).length) {
		    $("#" + $this.options[type].listItem + "_" + id).remove();
		}
		if ($("#" + $this.options[type].hiddenItem + "_" + id).length) {
		    $("#" + $this.options[type].hiddenItem + "_" + id).remove();
		}
		if (!$($this.options[type].listContainer).children().length) {
		    $($this.options[type].container).addClass("hide");
		}
	    },
	    error : errorFunction
	});
    }
    this.update = function(data, type){
	if (!data || !type || data.id === undefined) {
	    return;
	}
	type = type.toLowerCase();
	var $listContainer = $(this.options[type].listContainer);
	if (!$listContainer.length) {
	    showStatusMessage("Контейнер не найден", "error");
	    return;
	}	
	var li = this.createItem[type](data, type);	
	if (li) {	    
	    $listContainer.append(li);
	    var $hiddenContaner = $(this.options[type].hiddenContaner);
	    if (!$hiddenContaner.length) {
		showStatusMessage("Контейнер не найден", "error");
		return;
	    }	    
	    $hiddenContaner.append($("<input/>").attr({
		"name": this.options[type].hiddenName,
		"type":"hidden",
		"id": this.options[type].hiddenItem + "_" + data.id,
		"value": data.id
	    }));
	    
	    var $container = $(this.options[type].container);
	    if ($container.length){
		$container.removeClass("hide");
	    }	    	    
	}
    }
    
    this.createItem = {
	map : function(data, type) {
	    return $("<li/>").attr("id", $this.options[type].listItem + "_" + data.id)
	    .append($("<span/>").html(data.address))
	    .append($("<a/>").attr({
		"href" : "javascript:void(0)",
		"title" : "Удалить",
		"onclick" : "$.data(container, 'features').remove(" + data.id + ", '" + type + "')"
	    }).html("удалить"));
	},
	video : function(data, type) {
	    return $("<li/>").attr("id", $this.options[type].listItem + "_" + data.id)
	    .append($("<span/>").html(data.real_name))
	    .append($("<a/>").attr({
		"href" : "javascript:void(0)",
		"title" : "Удалить",
		"onclick" : "$.data(container, 'features').remove(" + data.id + ", '" + type + "')"
	    }).html("удалить"));
	},
	image : function(data, type) {
	    return $("<li/>").attr("id", $this.options[type].listItem + "_" + data.id)
	    .append($("<span/>").html(data.real_name))
	    .append($("<a/>").attr({
		"href" : "/up/" + data.path + "/thumb/" + data.thumb_name, 
		"title" : data.thumb_name,
		"rel" : "prettyPhoto"
	    }).html("посмотреть"))
	    .append($("<a/>").attr({
		"href" : "/up/" + data.path + "/origin/" + data.real_name,
		"title" : data.real_name,
		"rel" : "prettyPhoto"
	    }).html("оригинал"))
	    .append($("<a/>").attr({
		"href" : "javascript:void(0)",
		"title" : data.thumb_name,
		"onclick" : "$.data(container, 'features').remove(" + data.id + ", '" + type + "')"
	    }).html("удалить"));
	}
    }
}
Features.defaults = {
    map : {
	url : "/ajax/mapuploadremote",
	urlField : "#remoteMap",
	container : "#upMap",
	listContainer : "#mapList",
	hiddenContaner : "#upMap",
	submitButton : "#upRemoteMap",
	listItem : "advMap",
	hiddenItem : "hiddenMap",
	hiddenName : "features[map][]"	
    },
    image : {
	url : "/ajax/imageuploadremote",
	urlField : "#remoteImage",
	container : "#upImage",
	listContainer : "#imageList",
	hiddenContaner : "#upImage",
	submitButton : "#upRemoteImage",
	listItem : "advImage",
	hiddenItem : "hiddenImage",
	hiddenName : "features[image][]"	
    },
    video : {
	url : "/ajax/videouploadremote",
	urlField : "#remoteVideo",
	container : "#upVideo",
	listContainer : "#videoList",
	hiddenContaner : "#upVideo",
	submitButton : "#upRemoteVideo",
	listItem : "advVideo",
	hiddenItem : "hiddenVideo",
	hiddenName : "features[video][]"	
    }
}
